﻿using DLL;
using NursingFormSystem.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem.SpecialPopulationAssessmentForm
{
    public partial class HistorySPAF : Form
    {
        PatientInfo PatientInfo;
        public string Id = string.Empty;
        public HistorySPAF(PatientInfo patientInfo)
        {
            InitializeComponent();
            this.PatientInfo = patientInfo;
        }

        private void HistorySPAF_Load(object sender, EventArgs e)
        {
            string sql = "SELECT * FROM dbo.NursingFormRecord(NOLOCK) WHERE FormId = '{0}' AND PatientId='{1}' AND VisitId='{2}' ORDER BY AssessmentDate DESC";
            sql = string.Format(sql, (int)FormType.SpaForm, PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID);
            DataSet ds = SqlHelper.ExecuteDataset(sql, CommandType.Text);
            if (ds == null) return;
            if (ds.Tables.Count < 0) return;
            if (ds.Tables[0].Rows.Count <= 0) return;
            DataTable dt = ds.Tables[0];
            DataTable dtt = new DataTable();
            dtt.Columns.Add("Id", typeof(string));
            dtt.Columns.Add("AssessmentDate", typeof(string));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                object assessmentDate = row["AssessmentDate"];
                if (assessmentDate == DBNull.Value) assessmentDate = string.Empty;
                if (assessmentDate == null) assessmentDate = string.Empty;
                if (string.IsNullOrEmpty(assessmentDate.ToString())) assessmentDate = string.Empty;
                assessmentDate = Convert.ToDateTime(row["AssessmentDate"]).ToString("yyyy-MM-dd HH:mm");
                dtt.Rows.Add(
                    row["Id"].ToString(),
                    assessmentDate
                    );
            }
            gridControl1.DataSource = dtt;
        }

        #region 确认
        private void btnConfrim_Click(object sender, EventArgs e)
        {
            if (bandedGridView1.RowCount > 0)
            {
                string id = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "Id").ToString();
                Id = id;
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }
        #endregion

        #region 取消
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
        #endregion 

        #region 双击事件
        private void bandedGridView1_DoubleClick(object sender, EventArgs e)
        {
            if (bandedGridView1.RowCount > 0)
            {
                string id = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "Id").ToString();
                Id = id;
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }
        #endregion
        

    }
}
